Completed
Push — master ( 7c7ab7...45cb8f )
by Mathieu
19s queued 11s
created

User.getFullName   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
1
import {Entity, Column, PrimaryGeneratedColumn, Index} from 'typeorm';
2
3
export enum UserRole {
4
  COOPERATOR = 'cooperator',
5
  EMPLOYEE = 'employee',
6
  ACCOUNTANT = 'accountant'
7
}
8
9
@Entity()
10
export class User {
11
  @PrimaryGeneratedColumn('uuid')
12
  private id: string;
13
14
  @Column({type: 'varchar', nullable: false})
15
  private firstName: string;
16
17
  @Column({type: 'varchar', nullable: false})
18
  private lastName: string;
19
20
  @Column({type: 'varchar', unique: true, nullable: false})
21
  private email: string;
22
23
  @Index('api-token')
24
  @Column({type: 'varchar', nullable: true})
25
  private apiToken: string;
26
27
  @Column({type: 'varchar', nullable: false})
28
  private password: string;
29
30
  @Column({type: 'timestamp', nullable: true})
31
  private entryDate: string;
32
33
  @Column('enum', {enum: UserRole, nullable: false})
34
  private role: UserRole;
35
36
  @Column({type: 'timestamp', default: () => 'CURRENT_TIMESTAMP'})
37
  private createdAt: Date;
38
39
  constructor(
40
    firstName: string,
41
    lastName: string,
42
    email: string,
43
    apiToken: string,
44
    password: string,
45
    role: UserRole,
46
    entryDate?: string
47
  ) {
48
    this.firstName = firstName;
49
    this.lastName = lastName;
50
    this.email = email;
51
    this.apiToken = apiToken;
52
    this.password = password;
53
    this.role = role;
54
    this.entryDate = entryDate;
55
  }
56
57
  public getId(): string {
58
    return this.id;
59
  }
60
61
  public getFirstName(): string {
62
    return this.firstName;
63
  }
64
65
  public getLastName(): string {
66
    return this.lastName;
67
  }
68
69
  public getEmail(): string {
70
    return this.email;
71
  }
72
73
  public getApiToken(): string {
74
    return this.apiToken;
75
  }
76
77
  public getPassword(): string {
78
    return this.password;
79
  }
80
81
  public getEntryDate(): string {
82
    return this.entryDate;
83
  }
84
85
  public getRole(): UserRole {
86
    return this.role;
87
  }
88
89
  public getFullName(): string {
90
    return `${this.firstName} ${this.lastName}`;
91
  }
92
93
  public update(firstName: string, lastName: string, email: string): void {
94
    this.firstName = firstName;
95
    this.lastName = lastName;
96
    this.email = email;
97
  }
98
99
  public updatePassword(password: string): void {
100
    this.password = password;
101
  }
102
}
103